package com.wangijun.yuan.web.api;


import com.wangijun.yuan.web.base.CommonResult;
import com.wangijun.yuan.core.model.IdParam;
import com.wangijun.yuan.web.model.vo.ArticleContentVO;
import com.wangijun.yuan.web.model.vo.MainArticleVO;
import com.wangijun.yuan.web.service.ArticleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "4-文章内容页面")
@RestController
@RequiredArgsConstructor
@RequestMapping("/article")
public class ArticleContentController {
    private final ArticleService articleService;

    @Operation(summary = "文章内容", description = "文章主体内容")
    @PostMapping("/data")
    CommonResult<ArticleContentVO> data(@RequestBody @Validated IdParam param) {
        return CommonResult.data(articleService.data(param));
    }

    @Operation(summary = "推荐阅读", description = "推荐阅读列表，这个是可以写在和文章内容一起的，想了想，没必要！")
    @PostMapping("/recommend")
    CommonResult<List<MainArticleVO>> recommend(@RequestBody @Validated IdParam param) {
        return CommonResult.data(articleService.articleRecommend(param.getId()));
    }

    public record ArticleIdParam(
            @Schema(description = "文章ID")
            Long articleId
    ) {
    }

    @Operation(summary = "文章点赞", description = "文章点赞/取消点赞")
    @PostMapping("/star")
    CommonResult<Boolean> star(@RequestBody ArticleIdParam param) {
        boolean liked = articleService.star(param.articleId);
        return CommonResult.data(liked);
    }

    @Operation(summary = "文章收藏", description = "文章收藏/取消收藏")
    @PostMapping("/favorites")
    CommonResult<Boolean> favorites(@RequestBody ArticleIdParam param) {
        boolean liked = articleService.favorites(param.articleId);
        return CommonResult.data(liked);
    }

}
